package com.jhs.kjs.controller;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.jhs.kjs.dto.AdminPointPagingDTO;
import com.jhs.kjs.service.IAdminPointService;

@RequestMapping(value = "/admin")
@Controller
public class AdmimPointController {
	private static final Logger logger = LoggerFactory.getLogger(AdmimPointController.class);
	@Autowired
	IAdminPointService adminPointService;
	
	@RequestMapping(value = "/adminPointMain", method = {RequestMethod.GET, RequestMethod.POST})
	public ModelAndView adminPointMain(@ModelAttribute("paging") AdminPointPagingDTO paging){
		ModelAndView model = new ModelAndView("admin/point");
		model.addObject("totalPage", adminPointService.getAdminPointCount(paging));
		return model;
	}
	
	@RequestMapping(value = "/getAdminPointList", method = {RequestMethod.GET, RequestMethod.POST})
	public String getAdminPointList(HttpServletRequest req, Model model,@ModelAttribute("paging") AdminPointPagingDTO paging){
		model.addAttribute("totalPage", adminPointService.getAdminPointCount(paging));
		/*List<AdminPointPagingDTO> list = adminPointService.getAdminPointList(paging);
		for(AdminPointPagingDTO dto : list) {
			logger.debug(dto.getUserId());
			logger.debug(String.valueOf(dto.getPoint()));
			logger.debug(String.valueOf(dto.getPointRegiTime()));
			logger.debug(String.valueOf(dto.getPointIndex()));
			
		}*/
		model.addAttribute("pointList", adminPointService.getAdminPointList(paging));
		return "";
	}
	
	@RequestMapping(value = "/adminUsePointMain", method = {RequestMethod.GET, RequestMethod.POST})
	public ModelAndView adminUsePointMain(@ModelAttribute("paging") AdminPointPagingDTO paging){
		ModelAndView model = new ModelAndView("admin/point2");
		model.addObject("totalPage", adminPointService.getAdminUsePointCount(paging));
		return model;
	}
	
	@RequestMapping(value = "/adminUsePointList", method = {RequestMethod.GET, RequestMethod.POST})
	public String adminUsePointList(HttpServletRequest req, Model model,@ModelAttribute("paging") AdminPointPagingDTO paging){
		model.addAttribute("totalPage", adminPointService.getAdminUsePointCount(paging));
		model.addAttribute("pointList", adminPointService.getAdminUsePointList(paging));
		return "";
	}
	
}
